class MetaCalculator:
    def __init__(self, operator1, operator2):
        self.num1, self.num2 = operator1, operator2


class AddCalculator(MetaCalculator):
    def run(self):
        return self.num1 + self.num2


class SubCalculator(MetaCalculator):
    def run(self):
        return self.num1 - self.num2


class MultiplyCalculator(MetaCalculator):
    def run(self):
        return self.num1 * self.num2


class DivCalculator(MetaCalculator):
    def run(self):
        return self.num1 / self.num2


if __name__ == '__main__':

    operand_list = ['+', '-', '*', '%', '/']

    while True:
        num1 = input("请输入第一个数字(q to quit)>>>")
        try:
            num1 = float(num1)
        except Exception as e:
            print("输入有误")
            break

        num2 = input("请输入第二个数字(q to quit)>>>")
        try:
            num2 = float(num2)
        except Exception as e:
            print("输入有误")
            break

        operand = input("请输入运算符号>>>")
        if operand not in operand_list:
            print('没有此运算方法')
            continue

        if operand == "+":
            calculator = AddCalculator(num1, num2)

        elif operand == "-":
            calculator = SubCalculator(num1, num2)

        elif operand == "*":
            calculator = MultiplyCalculator(num1, num2)

        else:
            calculator = DivCalculator(num1, num2)

        res = calculator.run()
        print(res)


